package 笔试.米哈游;

import org.junit.Test;

import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;

public class two {
    @Test
    public void test() {

        System.out.println(cutString("我",1));
    }
    public String cutString (String original, int count) {
        StringBuilder sb =new StringBuilder();
        if(count ==0)return sb.toString();

        char[] c = original.toCharArray();
        int t=count;
        int i=0;
        while(i<c.length && t!=0){
            int zj=0;
            try {
                zj = (c[i]+"").getBytes("GBK").length;
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
            if(t>=zj){
                sb.append(c[i]);
                t-=zj;
                i++;
            }else{
                return sb.toString();
            }
        }
        return sb.toString();
    }
}
